/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"95A0ED64-8141-4471-B35F-26C2B50A7FF1",variableType:4}
 */
var f_edad = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"069F8E55-8E1C-4C12-91CC-83304B70D922",variableType:4}
 */
var f_hospital = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"723BCB9B-9E0C-4CA8-8EAE-9DF63F413FEA",variableType:4}
 */
var f_paciente = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"D3EA2772-6DBB-4D63-9772-8D2F458B887C",variableType:4}
 */
var f_caracteristica = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"021BA741-246F-45EA-9ED1-F315F9B05A51",variableType:4}
 */
var f_tipo_muestra = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"8B87ADFE-E66B-4C2E-85D9-8BBF122D1C58"}
 */
var f_codigo = null;

/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"A313D925-4204-4528-BE4D-5A47CCC25C78",variableType:93}
 */
var f_fecha = null;

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"14D1B288-D7F8-4E72-93F1-7C4D96D39F4F"}
 */
function ir_a_detalle(event) 
{
	globals.mostrarForm("muestras_dtl"); 
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"16FBDA1C-56C8-4966-B1CE-3C76BDBA1349"}
 * @AllowToRunInFind
 */
function buscar(event) {
	
	/** @type {String}*/
	var $where = ''
	var $args = new Array()
	
	if (f_fecha != null)
	{
		$where += ' and fecha between ? and ? '
		var $fecha1 = new Date(f_fecha.getFullYear(), f_fecha.getMonth(), f_fecha.getDate(),0,0,0,0)
		var $fecha2 = new Date(f_fecha.getFullYear(), f_fecha.getMonth(), f_fecha.getDate(),23,59,59,996)
		$args.push($fecha1)
		$args.push($fecha2)
	} 
	if (f_codigo != null)
	{
		$where += ' and upper(codigo) like upper(?) '
		$args.push('%' + f_codigo + '%')
	}
	if (f_paciente != null)
	{
		$where += ' and m.paciente_id = ? '
		$args.push(f_paciente)
	}
	if (f_tipo_muestra != null)
	{
		$where += ' and tipo_muestra_id = ? '
		$args.push(f_tipo_muestra)
	}	
	if (f_caracteristica != null)
	{
		$where += ' and caracteristica_id = ? '
		$args.push(f_caracteristica)
	}
	if (f_hospital != null)
	{
		$where += ' and hospital_id = ? '
		$args.push(f_hospital)
	}
	if (f_edad != null)
	{
		$where += ' and date_part(\'year\',fecha) - date_part(\'year\',p.fecha_nacimiento) > ? '
		$args.push(f_edad)
	}
	if ($where != '')
	{
		$where = $where.substring(4,$where.length)
	
		var $query = 'SELECT muestra_id FROM muestras "m" JOIN pacientes "p" ON p.paciente_id = m.paciente_id WHERE '+$where+' ORDER BY fecha'
		var $ds = databaseManager.getDataSetByQuery('cepario',$query,$args,-1)
		if ($ds.getMaxRowIndex() == 0)
		{
			globals.DIALOGS.showInfoDialog('Aviso','No se encontraron muestras con esas condiciones','OK')
		}
		controller.loadRecords($ds)
	}
	else
	{
		controller.loadAllRecords()
		controller.sort('fecha desc')
	}
	return true;
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"1138F1CE-8926-4C23-A607-0122E067E5FE"}
 */
function anular(event) 
{
	f_fecha  			= null
	f_codigo 			= null
	f_paciente 			= null
	f_tipo_muestra 		= null
	f_caracteristica 	= null
	f_edad				= null
	f_hospital			= null	
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"0D9CF4B5-5446-4A26-A757-8AAF24107ACA"}
 */
function nueva(event) {
	globals.formEnVentana('muestras_carga','MUESTRA_CARGA','Nueva Muestra')
}
